package com.tech.config

import com.typesafe.config.{Config, ConfigFactory}

import scala.collection.mutable

/**
 * 加载应用Application属性配置文件config.properties获取属性值
 */
object ApplicationConfig extends Serializable {

  // 加载属性文件,
  private val config: Config = {
    val condition = ConfigFactory.load("active.properties")
    ConfigFactory.load(s"${condition.getString("active.properties")}.properties")
  }
  lazy val PROJECT: String = System.getProperties.getProperty("project")

  lazy val KAFKA_BROKER: String = config.getString("kafka_broker")
  lazy val KAFKA_STARTING_OFFSETS: String = config.getString("kafka_starting_offsets")
  lazy val CUSTOMER_NODE_TOPIC: String = "customer_node_" + PROJECT
  lazy val CUSTOMER_NODE_GROUP_TOPIC: String = "customer_node_group_" + PROJECT
  lazy val DYNAMIC_CUSTOMER_TOPIC: String = "dynamic_customer_" + PROJECT

  lazy val KUDU_MASTER: String = config.getString("kudu_master")

  lazy val URL_MYSQL: String = config.getString("url_mysql")

  lazy val URL_PRESTO: String = config.getString("url_presto")

  lazy val TIMEZONE: String = config.getString("timezone")

  lazy val SPARK_LOCAL_DIR: String = config.getString("spark_local_dir")

  lazy val AES_KEY: String = config.getString("aes_key")

  lazy val EVENT_MAP: mutable.Map[String, String] = {
    val eventMap = mutable.HashMap[String, String]()
    val eventMapStr = config.getString("event_map").replace(" ", "")
    for (i <- eventMapStr.split(","); j = i.split("->"))
      eventMap.put(j(0), j(1))
    eventMap
  }
}
